﻿using System;
using System.ComponentModel;
using System.Data;
using NetBay.Core.DataAccess;
using NetBay.Core.Extensions;
using NetBay.Core.Log;

namespace Rio.Manager.DataAccess
{
    public class DA_User
    {
        #region Enum

        /// <summary>
        /// List of DB functions to access data
        /// </summary>
        private enum DbFunction
        {
            [DescriptionAttribute("P_USER_Create")]
            AddUser,
        }

        #endregion Enum

        #region Function

        /// <summary>
        /// Executes P_USER_Create
        /// </summary>
        /// <param name="login">The login.</param>
        /// <param name="password">The password.</param>
        /// <param name="email">The email.</param>
        /// <param name="firstName">The first name.</param>
        /// <param name="name">The name.</param>
        public static bool AddUser(string login, string password, string email, string firstName, string name)
        {
            try
            {
                LogManager.Instance().LogDebugFormat("Calling SP: '{0}'", DbFunction.AddUser.szGetDescription());
                LogManager.Instance().LogDebug("(login<" + login + ">password<" + password + ">email<" + email + ">firstName<" + firstName + ">name<" + name + ">)");
                var db = DbHelper.DataBase;

                var dbCommand = db.GetNewCommand(DbFunction.AddUser.szGetDescription(), false);
                db.AddInParameter(dbCommand, "p_Login", DbType.String, login);
                db.AddInParameter(dbCommand, "p_Password", DbType.String, password);
                db.AddInParameter(dbCommand, "p_EMail", DbType.String, email);
                db.AddInParameter(dbCommand, "p_FistName", DbType.String, firstName);
                db.AddInParameter(dbCommand, "p_Name", DbType.String, name);

                db.ExecuteNonQuery(dbCommand);
                return true;
            }
            catch (Exception ex)
            {
                LogManager.Instance().LogError("AddUser exception[" + ex.Message + "]");
            }
            return false;
        }

        #endregion Function

    }
}
